import axios from "axios";
const axiosInstance = axios.create({});

export function uploadFile(file, token, key) {
  var fd = new FormData();
  fd.append("token", token);
  fd.append("key", key);
  fd.append("file", file);

  return axiosInstance({
    method: "POST",
    url: "http://up.qiniu.com",
    data: fd,
    onUploadProgress: progressEvent => {
      const uploadPercent = Math.round(
        (progressEvent.loaded * 100) / progressEvent.total
      );
      console.log("upload percent", uploadPercent);
    }
  })
    .then(ret => {
      return ret;
    })
    .catch(err => {
      console.log("err", err);
    });
}
